1 using System.Collections.Generic;
2
3 namespace
Assets.Scripts
4 {
5     
public static class ServiceLocator
6     {
7         
private static readonly IDictionary<object, object> services;
8
9         
static ServiceLocator()
10         {
11             services =
new Dictionary<object, object>();
12         }
13
14         
public static void AddService<T>(T service) where T: class
15         {
16             services[
typeof (T)] = service;
17         }
18
19         
public static void RemoveService<T>() where T : class
20         {
21             services.Remove(
typeof (T));
22         }
23
24         
public static T GetService<T>() where T : class
25         {
26             
object service;
27
28             
if (services.TryGetValue(typeof (T), out service))
29             {
30                 
return (T) service;
31             }
32
33             
return default(T);
34         }
35     }
36 }



Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.516 lượt xem

Gõ tìm kiếm nhanh...